<template>
  <el-rate
    v-bind="{ ...item }"
    v-model="changeValue"
    clearable
    :texts="getTexts"
  />
</template>

<script name="TRate" setup lang="ts">
import { computed } from "vue";
import { formEmits, formItemProps, useFormItem } from "../hooks/useFormItemHook";

const props = defineProps({
  ...formItemProps
});

console.log(props);

const emits = defineEmits([...formEmits]);

const { changeValue } = useFormItem(props, emits, true);

const getTexts = computed(() => {
  // 如果数组第几项是空的 那就用前面有值的·那项填充
  const texts = props.item?.texts || ["非常糟糕", "失望", "一般", "满意", "惊喜"];
  for (let i = 0; i < props.item?.max; i++) {
    if (!texts[i]) {
      texts[i] = texts[i - 1];
    }
  }
  return texts;
});
</script>
